/*
 * Copyright (c) 2016- 2020 qolome.com Inc. All Rights Reserved.
 * ProjectName: qolome-knowledge
 * FileName: PromotionStrategyFactory.java
 * Author: jiangfeng@qolome.com
 * Date: 2020/3/15 下午3:20
 * LastModified: 2020/03/15 15:20:15
 */

package com.qolome.knowledge.design.pattern.strategy.demo.promotion;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
 * @author Qolome
 * @version V1.0
 * @Description 促销策略工厂
 * @date 2020年 03月15日 15:20:48
 */
public class PromotionStrategyFactory {

    private static Map<String,IPromotionStrategy> PROMOTION = new HashMap<>();
    private PromotionStrategyFactory() {
    }

    static {
        PROMOTION.put(PromotioKey.CONPON,new ConponStrategy());
        PROMOTION.put(PromotioKey.GROUPBUY,new GroupBuyStrategy());
        PROMOTION.put(PromotioKey.CASHBACK,new CashbackStrategy());
    }

    private static  final IPromotionStrategy EMPTY = new EmptyStrategy();


    public static IPromotionStrategy getPromotionStrategy(String key) {
        IPromotionStrategy strategy = PROMOTION.get(key);
        return Objects.isNull(strategy)?EMPTY:strategy;
    }



    private interface PromotioKey{
        String CONPON = "CONPON";
        String GROUPBUY = "GROUPBUY";
        String CASHBACK = "CASHBACK";
    }

    public static Set<String> getPromotionKeys(){

        return PROMOTION.keySet();
    }
}
